package com.ob.api;

import com.ob.api.limit.RateLimiterInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author xzzz
 */
@Slf4j
@ConditionalOnClass(value = RedisTemplate.class)
public class ApiMvcConfig implements WebMvcConfigurer {

    @Autowired
    private RateLimiterInterceptor apiLimiterInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(apiLimiterInterceptor).addPathPatterns("/**");
    }

}